<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var userIds = document.getElementsByName("userId");
		var sign = 0;
		for(var i = 0; i < userIds.length; i++){
			if(userIds[i].checked)sign = sign + 1;
		}
		if(sign <= 0){
			alert("<fmt:message key='common.message.wDiscard'/>");
			return false;
		}
		return true;
	}

	function back(){
		var sign = "<c:out value='${sign}'/>";
		var uri = "./customerManage.do";
		if(sign == '1'){
			uri = "./customerManage.do";
		}else if(sign == '2'){
			uri = "./contractCustomer.do";
		}
		window.location.href = uri;
		window.location.target = "main";
	}
	
	function updateShareCustomer(){
		var customerId = "<c:out value='${customerId}'/>";
		var sign = "<c:out value='${sign}'/>";
		window.location.href = "./customerManage.do?action=preUpdateShareCustomer&customerId="+customerId+"&sign="+sign;
		window.location.target = "main";
		//document.shareCustomerForm.action = "./customerManage.do?action=preUpdateShareCustomer&customerId="+customerId;
		//document.shareCustomerForm.target = "main";
		//document.shareCustomerForm.submit();
	}
	
	function deleteShareCustomer(){
		var sign = "<c:out value='${sign}'/>";
		if(checkForm()){
			document.shareCustomerForm.action = "./customerManage.do?action=deleteShareCustomer&sign="+sign;
			document.shareCustomerForm.target = "main";
			document.shareCustomerForm.submit();
		}
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("<fmt:message key='common.message.updateSuccess'/>");
		}else if("<c:out value='${result}'/>" == 3){
			alert("<fmt:message key='common.message.deleteSuccess'/>");
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="shareCustomerForm" action="" method="post">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab" colspan="3">
							共享客户
						</td>
					</tr>
					<tr>
						<td valign="bottom" class="a_tools" style="padding-left: 3px;">
							<a class="update" href="javascript:updateShareCustomer();" hidefocus="true"><fmt:message key='common.button.update'/></a>
							<a class="del" href="javascript:deleteShareCustomer();" hidefocus="true"><fmt:message key='common.button.delete'/></a>
						</td>
						<td></td>
						<td align="right" valign="bottom">
							<a href="javascript:back();" hidefocus="true">返回客户列表</a>&nbsp;&nbsp;
						</td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td class="title_lab">
							当前共享用户
						</td>
					</tr>
					<tr>
						<td>
							<table class="table">
								<tr>
									<td valign="top">
										<!-- 
										<div style="width:800px;height:100%;overflow-x: scroll;overflow-y: hidden;">
										 -->
										<table class="table_style">
											<tr>
												<td class="title" width="8"></td>
												<td class="title" width="30"><fmt:message key='common.lable.checkbox'/></td>
												<td class="title"><fmt:message key='customer.lable.empName'/></td>
												<td class="title"><fmt:message key='customer.lable.byDept'/></td>
												<td class="title"><fmt:message key='customer.lable.sharePri'/></td>
											</tr>
											<c:forEach var="customerShare" items="${customerShares}" varStatus="cs">
											<tr onmouseover="onmousemoveChange(this,'img${cs.count}')" onmouseout="onmouseoutChange(this,'img${cs.count}')">
												<td height="16" width="8" align="right"><img id="img${cs.count}" src="./images/table_sign2.bmp"></td>
												<td><input id="userId" name="userId" type="checkbox" value="${customerShare.salePersonId}" <c:if test='${customer.salePersonId == customerShare.salePersonId}'>disabled</c:if> /></td>
												<td>${customerShare.salePerson}</td>
												<td>${customerShare.deptName}</td>
												<td>
													<c:choose>
														<c:when test="${customerShare.isReadWrite == 1}"><fmt:message key='customer.select.write'/></c:when>
														<c:otherwise><fmt:message key='customer.select.read'/></c:otherwise>
													</c:choose>
												</td>
											</tr>
											</c:forEach>
										</table>
										<!-- 
										</div>
										 -->
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<input id="customerId" name="customerId" value="${customerId}" type="hidden"/>
</form>
</body> 
</html>